{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 41,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Wall time: 2.03 ms\n"
     ]
    }
   ],
   "source": [
    "%%time\n",
    "m = 10000\n",
    "temp = int(m ** 0.5) + 1\n",
    "lst = [2,3]\n",
    "for i in range(5,temp,2):\n",
    "    for j in range(2,int(i ** 0.5) + 1):\n",
    "        if not i % j:\n",
    "            break\n",
    "    else:\n",
    "        lst.append(i)\n",
    "st = set()\n",
    "for i in lst:\n",
    "    st |= set(range(i+i,m+1,i))\n",
    "res = set(range(2,m+1)) - st"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 37,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Wall time: 14 ms\n"
     ]
    }
   ],
   "source": [
    "%%time\n",
    "m = 10000\n",
    "lst = [2,3]\n",
    "for i in range(5,m,2):\n",
    "    for j in range(2,int(i ** 0.5) + 1):\n",
    "        if not i % j:\n",
    "            break\n",
    "    else:\n",
    "        lst.append(i)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "#第一种方法较快"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.2"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
